package com.boot.service.impl;

import com.boot.dao.AccountManagementDao;
import com.boot.entity.*;
import com.boot.service.IAccountManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class IAccountManagementServiceImpl implements IAccountManagementService {

    @Autowired
    public AccountManagementDao dao;

    @Override
    public List<User> findAllUser() {
        return dao.findAllUser();
    }

    @Override
    public List<User> findAllUser(String key) {
        return dao.findAllUser(key);
    }

    @Override
    public int findUserCount() {
        return dao.findUserCount();
    }

    @Override
    public int findUserCount(String key) {
        return dao.findUserCount(key);
    }

    @Override
    public int delUser(int id) {
        return dao.delUser(id);
    }

    @Override
    public User findUserById(int id) {
        return dao.findUserById(id);
    }

    @Override
    public int updateUser(User user) {
        return dao.updateUser(user);
    }

    @Override
    public int addUser(User user) {
        return dao.addUser(user);
    }

    @Override
    public User findUserByUserName(String username) {
        return dao.findUserByUserName(username);
    }

    @Override
    public Company findCompanyById(int id) {
        return dao.findCompanyById(id);
    }

    @Override
    public List<Company> findAllCompany() {
        return dao.findAllCompany();
    }

    @Override
    public List<Department> findAllDepartment() {
        return dao.findAllDepartment();
    }

    @Override
    public int nextPurchapplyID() {
        return dao.nextPurchapplyID();
    }

    @Override
    @Transactional
    public int addPurchaseRequest(Purchapply purchapply, PurchapplyDetail purchapplyDetail, CoalQuality coalQuality) {
        int count1 = dao.addPurchapply(purchapply);
        purchapplyDetail.setPurchapplyId(purchapply.getPurchapplyId());
        coalQuality.setPurchapplyId(purchapply.getPurchapplyId());

        int count2 = dao.addPurchapplyDetail(purchapplyDetail);
        int count3 = dao.addCoalQuality(coalQuality);
        return count1 + count2 + count3;
    }

    @Override
    @Transactional
    public int modifyPurchaseRequest(Purchapply purchapply, PurchapplyDetail purchapplyDetail, CoalQuality coalQuality) {
        int count1 = dao.modifyPurchapply(purchapply);
        int count2 = dao.modifyPurchapplyDetail(purchapplyDetail);
        int count3 = dao.modifyCoalQuality(coalQuality);
        return count1 + count2 + count3;
    }

    @Override
    @Transactional
    public int deletePurchaseRequest(int purchapply_id) {
        int count1 = dao.deletePurchapply(purchapply_id);
        int count2 = dao.deletePurchapplyDetail(purchapply_id);
        int count3 = dao.deleteCoalQuality(purchapply_id);
        return count1 + count2 + count3;
    }


    @Override
    public List<PurchapplyDetail> findPurchapplyDetailByCompanyId(int company_id) {
        return dao.findPurchapplyDetailByCompanyId(company_id);
    }

    @Override
    public int findPurchapplyDetailCountByCompanyId(int company_id) {
        return dao.findPurchapplyDetailCountByCompanyId(company_id);
    }

    @Override
    public Purchapply findPurchapplyById(int id) {
        return dao.findPurchapplyById(id);
    }

    @Override
    public PurchapplyDetail findPurchapplyDetailById(int purchapply_id) {
        return dao.findPurchapplyDetailById(purchapply_id);
    }

    @Override
    public CoalQuality findCoalQualityById(int purchapply_id) {
        return dao.findCoalQualityById(purchapply_id);
    }
}
